package com.thoughtworks.opensource.yui.dd.client.triads.constrainedgrid;

import com.thoughtworks.opensource.yui.dd.client.domain.MyNumber;

/**
 * Created by IntelliJ IDEA.
 * Author: C. K. Sidu Ponnappa
 * Date: Nov 29, 2006
 * Time: 12:45:03 AM
 * ThoughtWorks India Pvt. Ltd.
 */
public class ConstrainedNumbersCollection {
    private MyNumber[] numbers;


    public ConstrainedNumbersCollection() {
        numbers = new MyNumber[10];
        for (int i = 0; i < numbers.length; i++) {
            numbers[i] = new NullNumberImpl();
        }
    }

    public boolean addNumberAt(MyNumber number, int index){
        if(numberIsGreaterThanNumbersUpto(number, index) && isLessThanNumbersAfter(number,index)){
            numbers[index] = number;
            return true;
        }
        return false;
    }

    protected boolean isLessThanNumbersAfter(MyNumber number, int index) {
        return false;
    }

    protected boolean numberIsGreaterThanNumbersUpto(MyNumber number, int index) {
        int i;
        for (i = 0; i < index; i++) {
            MyNumber myNumber = numbers[i];
            if(number.isLessThan(myNumber)) break;
        }
        if(i != index) return false;
        return true;
    }
}
